package com.tedu.parkinglot.parklot.controller;

import com.tedu.parkinglot.base.response.JsonResult;
import com.tedu.parkinglot.parklot.pojo.dto.ParklotQuery;
import com.tedu.parkinglot.parklot.pojo.dto.ParklotSaveParam;
import com.tedu.parkinglot.parklot.pojo.vo.ParklotVO;
import com.tedu.parkinglot.parklot.service.ParklotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/parklot/")
public class ParklotController {
    @Autowired
    ParklotService parklotService;

    @GetMapping("select")
    public JsonResult select(ParklotQuery parklotQuery) {
        List<ParklotVO> list = parklotService.select(parklotQuery);
        return JsonResult.ok(list);
    }
    @GetMapping("list")
    public JsonResult parkingList() {
        ParklotQuery parklotQuery = new ParklotQuery();
        List<ParklotVO> list = parklotService.select(parklotQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(ParklotSaveParam parklotSaveParam) {
        log.debug("新增停车场：parklotSaveParam{}", parklotSaveParam);
        parklotService.save(parklotSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("删除停车场：id{}", id);
        parklotService.deleteParking(id);
        return JsonResult.ok();
    }
}
